package com.nova.bluetooth.widget;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.nova.bluetooth.R;
import com.nova.bluetooth.helpUtils.ToastUtils;
import com.nova.bluetooth.myEnum.KeyFunctionControlModel;
import com.shawnlin.numberpicker.NumberPicker;

public class KeyFunctionPickerCustom {
    private final NumberPicker model;
    private CommonDialog mDialog;
    public interface KeyFunctionPickerCallback {
        void setDate(Integer integer);
    }

    @SuppressLint("MissingInflatedId")
    public KeyFunctionPickerCustom(Activity context, KeyFunctionPickerCallback callback) {
        View dialogView = context.getLayoutInflater().inflate(R.layout.dialog_key_function_picker, null);
        mDialog = new CommonDialog(context, dialogView);
        mDialog.setWidth(R.dimen.dp_320);
        mDialog.setHeight(R.dimen.dp_370);
        mDialog.setCancelable(false);
        mDialog.setGravity(Gravity.CENTER);

        model = (NumberPicker) dialogView.findViewById(R.id.picker);
        String[] strNum = {"音量加", "音量减", "上一曲","下一曲", "播放/暂停"}; // 直接初始化数组
        model.setMinValue(0);
        model.setMaxValue(strNum.length - 1);
        model.setDisplayedValues(strNum);
        model.setValue(1);

        // 取消按钮和确定按钮事件绑定
        View cancel = dialogView.findViewById(R.id.cancel);
        View ok = dialogView.findViewById(R.id.ok);
        if (cancel != null) {
            cancel.setOnClickListener(v -> mDialog.dismissDialog());
        }
        if (ok != null) {
            ok.setOnClickListener(v -> {
                mDialog.dismissDialog();
                callback.setDate(model.getValue());
            });
        }
    }


    public void show() {
        mDialog.showDialog();
    }

    public void setValue(int mValue) {
        model.setValue(mValue);
    }

}
